home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / SoundApps / aa_Intel_Only / EnvelopeEd1.04b / Source / Controller.m < prev    next >
Encoding:
Text File  |  1993-04-02  |  8.0 KB  |  367 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "Controller.h"
  5. #import "EnvelopeView.h"
  6. #import <appkit/Application.h>
  7. #import <appkit/Panel.h>
  8. #import <appkit/Button.h>
  9. #import <appkit/ButtonCell.h>
  10. #import <appkit/Cell.h>
  11. #import <appkit/ActionCell.h>
  12. #import <appkit/Matrix.h>
  13. #import <appkit/View.h>
  14. #import <appkit/Form.h>
  15. #import <appkit/Listener.h>
  16. #import <appkit/PopUpList.h>
  17. #import    <appkit/NXSplitView.h>
  18. #import    <objc/List.h>
  19. #import <stdlib.h>
  20. #import <ctype.h>
  21. #import <math.h>
  22.  
  23. extern NXDefaultsVector envelopeDefaults;
  24.  
  25. @implementation Controller
  26.  
  27. - appDidInit:sender
  28. {
  29.     lastDeleted=NULL;
  30.     theEnvelope=NULL;
  31.     myListener=[NXApp appListener];
  32.     [myListener setServicesDelegate: self];
  33.     [theWindow makeKeyAndOrderFront: self];
  34.     NXRegisterDefaults("EnvelopeEd",envelopeDefaults);
  35.     [self addEnvelope: self];
  36.     return self;
  37. }
  38.  
  39. - infoPanel:sender
  40. {
  41.     if(!infoPanel) {
  42.         [NXApp loadNibSection:"Info.nib" owner:self];
  43.     }
  44.     [infoPanel makeKeyAndOrderFront:sender];
  45.     return self;
  46. }
  47.  
  48. - helpPanel:sender
  49. {
  50.     if(!helpPanel) {
  51.         [NXApp loadNibSection:"Info.nib" owner:self];
  52.     }
  53.     [helpPanel makeKeyAndOrderFront:sender];
  54.     return self;
  55. }
  56.  
  57. //===================================================================
  58. // Operations on Envelopes
  59. //===================================================================
  60.  
  61. - addEnvelope:sender
  62. {
  63.     id old;
  64.     
  65.     NXRect * theFrame;
  66.     theFrame = malloc (sizeof (NXRect));
  67.     [theSplitView getFrame: theFrame];
  68.     old=theEnvelope;
  69.     if (old!=NULL) [old dim];
  70.     theEnvelope=[[EnvelopeView alloc] initFrame: theFrame];
  71.     [theEnvelope controllerIs: self];
  72.     [theSplitView addSubview: theEnvelope];
  73.     [theSplitView adjustSubviews];
  74.     [theSplitView display];
  75.     [theWindow makeFirstResponder: theEnvelope];
  76.     if (old!=NULL && [theLinkX state]==1) 
  77.         [self broadcastXLimitsOf: old];
  78.     free (theFrame);
  79.     return self;
  80. }
  81.  
  82. - removeEnvelope:sender
  83. {
  84.     id views;
  85.     unsigned int lastIndex;
  86.     
  87.     if (theEnvelope!=NULL) {
  88.         lastIndex=[[theSplitView subviews] 
  89.             indexOf: theEnvelope];                // where is on the subview list?
  90.         lastDeleted=[theEnvelope copy];            // remember last envelope...
  91.         [theEnvelope removeFromSuperview];        // ...but delete it from the window!
  92.         views=[theSplitView subviews];
  93.         if ([views count]==0)                    // define pointer to new envelope
  94.             theEnvelope=NULL;
  95.         else {
  96.             if ((theEnvelope=[views objectAt: lastIndex])==NULL)
  97.                 theEnvelope=[views objectAt: 0];
  98.         }
  99.         if (theEnvelope!=NULL)
  100.             [theWindow makeFirstResponder: theEnvelope];
  101.         
  102.         [theSplitView adjustSubviews];            // display new split view
  103.         [theSplitView display];
  104.     }
  105.     return self; 
  106. }
  107.  
  108. - unRemoveEnvelope:sender
  109. {
  110.     id old;
  111.     
  112.     if (lastDeleted!=NULL) {                    // only if previous delete
  113.         [theSplitView addSubview: lastDeleted];
  114.         old=theEnvelope;
  115.         if (old!=NULL) [old dim];
  116.         theEnvelope=lastDeleted;                // set new current envelope
  117.         lastDeleted=NULL;
  118.         [theWindow makeFirstResponder: theEnvelope];
  119.         if (old!=NULL && [theLinkX state]==1) 
  120.             [self broadcastXLimitsOf: old];
  121.         [theSplitView adjustSubviews];
  122.         [theSplitView display];
  123.     }
  124.     return self;
  125. }
  126.  
  127. - update: sender
  128. {
  129.     int point;
  130.     
  131.     if (theEnvelope!=NULL && theEnvelope!=sender)
  132.         [theEnvelope dim];
  133.     if (theEnvelope!=sender) {
  134.         theEnvelope=sender;
  135.         [theEnvelope highlight];
  136.         [theWindow makeFirstResponder: theEnvelope];
  137.     }
  138.     point=[sender getPoint];
  139.     [thePoint setIntValue: point];
  140.     [theXCoord setFloatValue: [sender getX: point]];
  141.     [theYCoord setFloatValue: [sender getY: point]];
  142.     [theYrCoord setFloatValue: [sender getYr: point]];
  143.     [theSmoothing setFloatValue: [sender getSmoothing: point]];
  144.     [theSmoothSlider setFloatValue: [sender getSmoothing: point]];
  145.     [theXMinCoord setFloatValue: [sender getXMin]];
  146.     [theXMaxCoord setFloatValue: [sender getXMax]];
  147.     [theYMinCoord setFloatValue: [sender getYMin]];
  148.     [theYMaxCoord setFloatValue: [sender getYMax]];
  149.     [theXSnapCoord setFloatValue: [sender getXSnap]];
  150.     [theYSnapCoord setFloatValue: [sender getYSnap]];
  151.     [theStickyPoint setState: [sender getSticky: point]];
  152.     [theGraphType setState: [sender getShowSmooth]];
  153.     return self;
  154. }
  155.  
  156. - updateCoords: sender at: (int)point
  157. {
  158.     [theXCoord setFloatValue: [sender getX: point]];
  159.     [theYCoord setFloatValue: [sender getY: point]];
  160.     [theYrCoord setFloatValue: [sender getYr: point]];
  161.     return self;    
  162. }
  163.  
  164. //===================================================================
  165. // Pasteboard interface methods
  166. //===================================================================
  167.  
  168. - copy:sender
  169. {
  170.     if (theEnvelope!=NULL)
  171.         return [theEnvelope copy: sender];
  172.     return self;
  173. }
  174.  
  175. - paste:sender
  176. {
  177.     if (theEnvelope!=NULL)
  178.         return [theEnvelope paste: sender];
  179.     return self;
  180. }
  181.  
  182. //===================================================================
  183. // Messages received from panel buttons and fields to update parameters
  184. //===================================================================
  185.  
  186. - nextPoint:sender
  187. {
  188.     if (theEnvelope!=NULL) [theEnvelope nextPoint];
  189.     return self;
  190. }
  191.  
  192. - previousPoint:sender
  193. {
  194.     if (theEnvelope!=NULL) [theEnvelope previousPoint];
  195.     return self;
  196. }
  197.  
  198. - setPoint:sender
  199. {
  200.     if (theEnvelope!=NULL) [theEnvelope setPointTo: [sender intValue]];
  201.     return self;
  202. }
  203.  
  204. - setXValue:sender
  205. {
  206.     if (theEnvelope!=NULL) 
  207.         [theEnvelope setXAt: [thePoint intValue] to: [sender floatValue]];
  208.     return self;
  209. }
  210.  
  211. - setYValue:sender
  212. {
  213.     if (theEnvelope!=NULL) 
  214.         [theEnvelope setYAt: [thePoint intValue] to: [sender floatValue]];
  215.     return self;
  216. }
  217.  
  218. - setYrValue:sender
  219. {
  220.     if (theEnvelope!=NULL) 
  221.         [theEnvelope setYrAt: [thePoint intValue] to: [sender floatValue]];
  222.     return self;
  223. }
  224.  
  225. - setSmoothValue:sender
  226. {
  227.     float smooth;
  228.     
  229.     smooth=[sender floatValue];
  230.     smooth=rint(smooth*1000)/1000;
  231.     [theSmoothSlider setFloatValue: smooth];
  232.     if (theEnvelope!=NULL) 
  233.         [theEnvelope setSmoothAt: [thePoint intValue] to: smooth];
  234.     return self;
  235. }
  236.  
  237. - setSmoothFromSlider:sender
  238. {
  239.     float smooth;
  240.     
  241.     smooth=[sender floatValue];
  242.     smooth=rint(smooth*1000)/1000;
  243.     [theSmoothing setFloatValue: smooth];
  244.     if (theEnvelope!=NULL) 
  245.         [theEnvelope setSmoothAt: [thePoint intValue] to: smooth];
  246.     return self;
  247. }
  248.  
  249. - broadcastXLimitsOf:envelope
  250. {
  251.     unsigned int i;
  252.     List * envelopes;
  253.     double max, min;
  254.     
  255.     min=[envelope getXMin];
  256.     max=[envelope getXMax];
  257.     envelopes=[theSplitView subviews];
  258.     for (i=0; i<[envelopes count]; i++)
  259.         [[envelopes objectAt: i] setXLimitsTo:min :max];
  260.     return self;
  261. }
  262.  
  263. - setXMinValue:sender
  264. {
  265.     if (theEnvelope!=NULL) {
  266.         [theEnvelope setXMinTo: [sender floatValue]];
  267.         if ([theLinkX state]==1) 
  268.             [self broadcastXLimitsOf: theEnvelope];
  269.     }
  270.     return self;
  271. }
  272.  
  273. - setXMaxValue:sender
  274. {
  275.     if (theEnvelope!=NULL) {
  276.         [theEnvelope setXMaxTo: [sender floatValue]];
  277.         if ([theLinkX state]==1) 
  278.             [self broadcastXLimitsOf: theEnvelope];
  279.     }
  280.     return self;
  281. }
  282.  
  283. - setYMinValue:sender
  284. {
  285.     if (theEnvelope!=NULL) {
  286.         [theEnvelope setYMinTo: [sender floatValue]];
  287.     }
  288.     return self;
  289. }
  290.  
  291. - setYMaxValue:sender
  292. {
  293.     if (theEnvelope!=NULL) {
  294.         [theEnvelope setYMaxTo: [sender floatValue]];
  295.     }
  296.     return self;
  297. }
  298.  
  299. - setXSnapValue:sender
  300. {
  301.     if (theEnvelope!=NULL) {
  302.         [theEnvelope setXSnapTo: [sender floatValue]];
  303.     }
  304.     return self;
  305. }
  306.  
  307. - setYSnapValue:sender
  308. {
  309.     if (theEnvelope!=NULL) {
  310.         [theEnvelope setYSnapTo: [sender floatValue]];
  311.     }
  312.     return self;
  313. }
  314.  
  315. - setStickyPoint:sender
  316. {
  317.     if (theEnvelope!=NULL) 
  318.         [theEnvelope setStickyAt: [thePoint intValue] To: [sender state]];
  319.     return self;
  320. }
  321.  
  322. - setGraphType:sender
  323. {
  324.     if (theEnvelope!=NULL) 
  325.         [theEnvelope setShowSmooth: [sender state]];
  326.     return self;
  327. }
  328.  
  329. - setDrawSegmentsState:sender
  330. {
  331.     if (theEnvelope!=NULL) {
  332.         if ([theEnvelope getDrawSegments]==-1)
  333.         [theEnvelope setDrawSegments: 0];
  334.         else
  335.             [theEnvelope setDrawSegments: -1];
  336.     }
  337.     return self;
  338. }
  339.  
  340. - setLinkX:sender
  341. {
  342.     if (theEnvelope!=NULL && [sender state]==1) 
  343.         [self broadcastXLimitsOf: theEnvelope];
  344.     return self;
  345. }
  346.  
  347. - reScaleLimits:sender;
  348. {
  349.     if (theEnvelope!=NULL) {
  350.         [theEnvelope scaleLimits];
  351.         if ([theLinkX state]==1) 
  352.             [self broadcastXLimitsOf: theEnvelope];
  353.     }
  354.     return self;
  355. }
  356.  
  357. //===================================================================
  358. // Messages received from the envelope to query for parameters
  359. //===================================================================
  360.  
  361. - (const char *)getStyle
  362. {
  363.     return [[[theOutputTypes cell] target] selectedItem];
  364. }
  365.  
  366. @end
  367.